package cn.bluemobi.platform.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.bluemobi.common.core.dto.MapDto;
import cn.bluemobi.common.core.dto.Page;
import cn.bluemobi.common.core.dto.PageCondition;
import cn.bluemobi.platform.core.mybatis.PageUtils;
import cn.bluemobi.platform.entity.banner.Banner;
import cn.bluemobi.platform.entity.system.User;
import cn.bluemobi.platform.mapper.BannerMapper;
import cn.bluemobi.platform.service.BannerService;

@Service
@Transactional
public class BannerServiceImpl implements BannerService {

	@Autowired
	private BannerMapper bannerMapper;

	@Override
	public List<Map<String, Object>> findCommodityList() {
		return bannerMapper.findCommodityList();
	}

	@Override
	public Page<Map<String, Object>> findBanners(PageCondition cond) {
		Page<Map<String, Object>> page = PageUtils.startPage(cond);
		page.setList(bannerMapper.findBanners(cond.getMap()));
		return page;
	}

	@Override
	public Banner findBannerDetail(String bannerId) {
		Banner banner = bannerMapper.findBannerDetail(bannerId);
		if (banner != null) {
		}
		return banner;
	}

	@Override
	public MapDto saveOrUpdate(Banner banner, User user) {
		MapDto dto = new MapDto();
		if (StringUtils.isEmpty(banner.getBannerId())) {
			bannerMapper.insertBanner(banner);

		} else {
			bannerMapper.updateBanner(banner);
		}
		return dto;
	}

	@Override
	public MapDto deleteBanner(String bannerId, User user) {
		MapDto dto = new MapDto();
		bannerMapper.deleteBanner(bannerId);
		return dto;
	}

}
